import { KKHandler, KKP2D } from '@coldcloude/kakera';
import { _decorator, Component } from 'cc';
const { ccclass } = _decorator;

@ccclass('CharacterController')
export class CharacterController extends Component {
    //move
    moveHandler:KKHandler<KKP2D>;
    move(delta:KKP2D){
        if(this.moveHandler){
            this.moveHandler(delta);
        }
    }
    onMove(handler:KKHandler<KKP2D>){
        this.moveHandler = handler;
    }
    //moveTo
    moveToHandler:KKHandler<KKP2D>;
    moveTo(target:KKP2D){
        if(this.moveToHandler){
            this.moveToHandler(target);
        }
    }
    onMoveTo(handler:KKHandler<KKP2D>){
        this.moveToHandler = handler;
    }
    //set direction and action
    setDirectionActionHandler:KKHandler<{
        direction?: number,
        action?: number
    }>;
    setDirectionAction(param:{
        direction?: number,
        action?: number
    }){
        if(this.setDirectionActionHandler){
            this.setDirectionActionHandler(param);
        }
    }
    onSetDirectionAction(handler:KKHandler<{
        direction?: number,
        action?: number
    }>){
        this.setDirectionActionHandler = handler;
    }
}
